<?php
/**
 * [PHPFOX_HEADER]
 */

defined('PHPFOX') or exit('NO DICE!');

/**
 *
 *
 * @copyright		[PHPFOX_COPYRIGHT]
 * @author  		Raymond Benc
 * @package 		Phpfox_Ajax
 * @version 		$Id: ajax.class.php 3642 2011-12-02 10:01:15Z Miguel_Espinoza $
 */
class Marketplace_Component_Ajax_Store_Ajax extends Phpfox_Ajax
{
    public function showMap(){
        $iId = $this->get("id");
        $sPlace = $this->get("place",'marketplace');
        $aStore = Phpfox::getService("marketplace.store")->getStoreFromListing($iId);
        if(empty($aStore))
            return false;
        
        $this->call("showListingMap(".$iId.",'".$aStore["full_address"]."','".$sPlace."');");
    }
    public function createAlbum(){
        Phpfox::isUser(true);
        $sAlbumName = $this->get('albumName');
        $sAlbumType= $this->get('albumType');
        if(empty($sAlbumName)){
            $this->call("createAlbumMessage('Invalid Album Name','error');");
            return false;
        }
        if($sAlbumType == 'marketplace'){
            $iId = Phpfox::getService("marketplace.store.album")->create($sAlbumName);
        }
        else{
            $iId = Phpfox::getService("photo.album.process")->add(array(
                'name' => $sAlbumName,
                'privacy' => 0,
                'privacy_comment' => 0,
                'description' => "Palxi Photo Album"
            ));
        }
        if($iId > 0){
            $this->call("createAlbumSuccess('".$iId."','".$sAlbumName."');");
        }
        else{
            $this->call("createAlbumMessage('Unable to create album','error');");
            return false;
        }
        return true;
    }
    public function order(){
        Phpfox::getBlock('marketplace.store.order');
    }
    public function open(){
        Phpfox::getBlock("marketplace.open",array("id" => $this->get("id",false)));
    }
    
    public function imagePreview(){
        $sLink = $this->get("link");
        Phpfox::getBlock("marketplace.media.photo",array('link' => $sLink));        
        $this->call("$('#image_preview_holder').html('".$this->getContent()."');$('#image_preview_holder').show();");
        $this->call('$Core.loadInit();');
    }
    public function videoPreview(){
        Phpfox::getBlock("link.preview");        
        $this->call("$('#video_preview_holder').html('".$this->getContent()."');");
        $this->call('$Core.loadInit();');
    }
    
    public function changePhoto(){
        Phpfox::getBlock("marketplace.store.changephoto",array(
            'id' => $this->get("id"),
            'iListingId' => $this->get("iListingId")
        ));
    }
    
    public function edit(){
        Phpfox::getBlock("marketplace.store.edit",array(
            'id' => $this->get("id"),
            'iListingId' => $this->get("iListingId")
        ));
    }
    
    public function update(){
        Phpfox::getBlock("marketplace.store.edit",array(
            'id' => $this->get("id"),
            'iListingId' => $this->get("listing_id")
        ));
        if($iReturnStoreSetting = $this->get('return_store_setting')){
            $this->call('window.location="'.Phpfox::getLib('url')->makeUrl('marketplace.setting',array('id'=> $this->get("id"), 'updated' => 1)).'";');
            //Phpfox::getLib('url')->send('marketplace.setting',array('id'=> $this->get("id"), 'updated' => 1));
            return true;
        }
        $aListing = Phpfox::getService("marketplace")->getListing($this->get("listing_id"));
        Phpfox::getBlock("marketplace.store.info",array("aListing" => $aListing));
        
        $this->call("$('#listing_store_header').html('".$this->getContent()."')");
    }
    
}

?>